if(!exists('g:previewCount'))
    let g:previewCount=0
endif

let s:dir= expand("<sfile>:p:h").'/'
function! preview#preview(urlOrFile,parms)
    call python#start_server()
    if g:previewCount <= 0
        let g:previewCount =0
       exec 'py3f ' .s:dir .'python/brower/brower.py'
    endif
    
    let g:previewCount +=1
    if a:parms == ''
        exec 'py3 webBrower.openUrl("' .a:urlOrFile .'"'  .')'
    else
        exec 'py3 webBrower.openUrl("' .a:urlOrFile .'",parms=' .a:parms .')'
    endif
endfunction

function preview#exit()
    if g:previewCount > 0
        py3 webBrower.close()
        let g:previewCount=0
    else
       let g:previewCount -=1
    endif
endfunction

